// Package goffmpeg 如果没有设置全局的ffmpeg path 请手动传入ffmpeg 可执行文件路径
package goffmpeg

import (
	"bytes"
	"os/exec"
)

// GoFFmpeg struct
type GoFFmpeg struct {
	FFmpeg string // bin path
	Amr    string // path
	Speex  string // path
	Mp3    string // path
}

// AmrToMp3 use ffmpeg amr to mp3 windows use poweshell
func (gff *GoFFmpeg) AmrToMp3() (out string, status bool, err error) {
	if gff.FFmpeg == "" {
		gff.FFmpeg = "ffmpeg"
	}
	command := gff.FFmpeg + " -i " + gff.Amr + " " + gff.Mp3
	var stderr bytes.Buffer
	cmd := exec.Command("powershell", "-c", command)
	cmd.Stderr = &stderr
	err = cmd.Run()
	return stderr.String(), cmd.ProcessState.Success(), err
}

// SpeexToMp3 use ffmpeg speex to mp3 windows use poweshell
func (gff *GoFFmpeg) SpeexToMp3() (out string, status bool, err error) {
	if gff.FFmpeg == "" {
		gff.FFmpeg = "ffmpeg"
	}
	command := gff.FFmpeg + " -i " + gff.Amr + " " + gff.Mp3
	var stderr bytes.Buffer
	cmd := exec.Command("powershell", "-c", command)
	cmd.Stderr = &stderr
	err = cmd.Run()
	return stderr.String(), cmd.ProcessState.Success(), err
}
